const connection = require('../app/database')

class PermissionService {
  async checkMoment(userId,momentId) {
    const statement = `SELECT * FROM moment WHERE user_id = ? AND id = ?`
    const [result] = await connection.execute(statement, [userId, momentId])
    return !!result.length
  } 

  async checkResouce(resouceName,resouceId, userId) {
    const statement = `SELECT * FROM ${resouceName} WHERE user_id = ? AND id = ?`
    const [result] = await connection.execute(statement, [userId, resouceId])
    return !!result.length
  } 
}

module.exports = new PermissionService()
